/**	
 * Title: CSE 5322 - Software Design Patterns
 * Description: 
 * Copyright: Copyright (c) UT Arlington, 2011
 * @author: Duy Nguyen(duyanh@uta.edu), Vivek Maheshwari(vivekm@uta.edu), Arjun Satish(arjun.satish@mavs.uta.edu), Lakshmana Srinivasa(lakshmana.srinivasa@mavs.uta.edu), Ismat Jahan(ismat.jahan@mavs.uta.edu)
 * @version 1.0
 */

package edu.uta.cse5322_2011_team3;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;

/**
 * 
 * @author duyanh at uta dot edu
 */
public class ContextHelp {
	private HashMap<String, String> dictionary;
	private static ContextHelp instance;

	private ContextHelp() {
		dictionary = new HashMap<String, String>();
		readHelpFile();
	}

	private void readHelpFile() {

		File f = new File("HelpFile.txt");
		String line = null;
		try {
			BufferedReader reader = new BufferedReader(new FileReader(f));
			while ((line = reader.readLine()) != null) {
				String[] tokens = line.split(":");
				if (tokens != null && tokens.length > 0) {
					dictionary.put(tokens[0], tokens[1]);
//					System.out.println("Key: " + tokens[0] + " Value: "
//							+ dictionary.get(tokens[0]));
				}
			}
		} catch (FileNotFoundException e) {
//			System.out.println("File not found:" + e);
		} catch (IOException e) {
                   
                    System.out.println("IO exception while reading file :" + e);
		}

	}

	public static ContextHelp getInstance() {
		if (instance == null) {
			instance = new ContextHelp();
		}

		return instance;
	}

	public String get(String identification) {
		String val = null;
		if (identification != null && dictionary.containsKey(identification))
			val = dictionary.get(identification);
		return val;
	}

//	public static void main(String argsp[]) {
//		ContextHelp help = new ContextHelp();
//		// help.readHelpFile();
//	}
}
